<?php

class linesinfoform extends basis
{
	function index(){
		$filter = urldecode($this->spArgs("filter"));
		$classid = $this->spArgs("classid");
		$this->filter = $filter;  // 获取搜索关键字
		$this->sclassid = $classid;  // 获取搜索关键字
		// 列出信息内容 且 修改分类名称
	    $user = spClass('linesinfo'); 
		if(empty($filter) && empty($classid))
		{ 
		  $conditions = "releasedate >= '".date('Ymd',strtotime("-15 day"))."'";
		  $results = $user->findAll($conditions,'id DESC',NULL,"150"); 
		}
		elseif(!empty($classid))
		{
		  $conditions = array( 'cityid' => $classid );
		  $results = $user->findAll($conditions,"id desc");  // 分页		
		}
		else
		{
		  $conditions = 'title like '.$user->escape('%'.$filter.'%');
		  $results = $user->findAll($conditions,"id desc");  // 分页		
		}
		$i=0;
		while( $i <= count($results)-1)
	    {		  
		  $conditions = array( 'id' => $results[$i]['cityid'] );
		  $c_name = spClass('lib_cityinfo'); 
		  $c_result = $c_name->findAll($conditions); 
		  $results[$i]['cityid'] = $c_result[0]['citystate'];
		  $i++;
		}
		$this->results = $results; 
		// 列出信息内容
		
		$cataObj = spClass("lib_cityinfo");
		$this->resultclass = $cataObj->getCatalogSub();
		
		$cataObj = spClass("lib_cityinfo");
		$this->resultsub = $cataObj->getCatalogList();
		
		$rulesinfo = spClass('chain'); 
		$conditions = array( 'used' => 1 );
        $chainresult = $rulesinfo->findAll($conditions);  // 分页
		$this->chainresult = $chainresult; 
	
		$id = $this->spArgs("id");
		$conditions = array( 'id' => $id );
		$e_user = spClass('linesinfo'); 
        $e_result = $e_user->findAll($conditions); 
		$this->id = $id; 
		$this->id = $e_result[0]['id']; 
		$this->username = $e_result[0]['username'];
		$this->userid = $e_result[0]['userid'];
		$this->picurl = $e_result[0]['picurl'];
		$this->title = $e_result[0]['title'];
		if(!empty($e_result[0]['releasedate'])){
		 $this->releasedate = date('Y-m-d H:i:s',$e_result[0]['releasedate']); 
		}		
		$this->content = $e_result[0]['content']; 
        $this->provinceid = $e_result[0]['provinceid']; 
		$this->cityid = $e_result[0]['cityid']; 
		$this->areaid = $e_result[0]['areaid']; 
		$this->map = $e_result[0]['map']; 
		$this->tags = $e_result[0]['tags']; 
		$this -> display('admin/content/lines.html');
	}

	function show(){
		$this->id = $this->spArgs("id");
		$conditions = array( 'id' => $this->id);
		$s_lines = spClass('linesinfo'); 
		$this->show = $s_lines->find($conditions); 
		//dump($this->show);

		// 省
		$conditions_province = array( 'id' => $this->show['provinceid'] );
		$t_province = spClass('lib_cityinfo'); 
		$this->province = $t_province->find($conditions_province); 
        // 市
		$conditions_city = array( 'id' => $this->show['cityid'] );
		$t_city = spClass('lib_cityinfo'); 
		$this->city = $t_city->find($conditions_city); 
        // 区
		$conditions_area = array( 'id' => $this->show['areaid'] );
		$t_area = spClass('lib_cityinfo'); 
		$this->area = $t_area->find($conditions_area); 

		if($this->show == null)
		{
			import(APP_PATH.'/tpl/404.php');exit();
		}
		else
		{
	        $conditions_youji = array('types'=>'lines','linkid' => $this->id);
			$s_youji = spClass('youjiinfo'); 
			$this->youji = $s_youji->findAll($conditions_youji);
			//dump($this->youji);

	        $conditions_answers = array('types'=>'lines','linkid' => $this->id);
			$s_answers = spClass('answersinfo'); 
			$this->answers = $s_answers->findAll($conditions_answers);
			//dump($this->answers);

	        $conditions_locals = array( 'types'=>'lines','linkid' => $this->id);
			$s_locals = spClass('localsinfo'); 
			$this->locals = $s_locals->findAll($conditions_locals); 

	        $conditions_visits = array('types'=>'lines','linkid' => $this->id);
			$s_visits = spClass('visitsinfo'); 
			$this->visits = $s_visits->findAll($conditions_visits); 

			$conditions_comment = array( 'types' => 'lines','linkid' => $this->id);
			$s_comment = spClass('commentinfo'); 
			$this->comment = $s_comment->findAll($conditions_comment); 

			$conditions_reply = array( 'types' => 'lines','linkid' => $this->id);
			$s_reply = spClass('replyinfo'); 
			$this->reply = $s_reply->findAll($conditions_reply); 

			$conditions_album = array('types' => 'lines','linkid' => $this->id);
			$s_album = spClass('albuminfo'); 
			$this->album = $s_album->findAll($conditions_album); 
			// ===================================
			$this->types = 'lines';
			$this->linkid = $this->spArgs("id");

			$this->provinceid = $_SESSION["quser"]['provinceid'];
			$this->cityid = $_SESSION["quser"]['cityid']; 

			$this->username = $_SESSION["quser"]['realname'];
			$this->userid = $_SESSION["quser"]['uid'];	
			
			$this -> display('content/lines.html');
	    }
	}

	function add(){
		//dump($this->current_url);
		if(empty($_SESSION["quser"]['uid']))
		{$this->error("你没有登录哦！请先登录...", spUrl("login","index")."?url=".$this->current_url);}

		$cataObj = spClass("lib_cityinfo");
		$this->resultclass = $cataObj->getCatalogSub();
		
		$cataObj = spClass("lib_cityinfo");
		$this->resultsub = $cataObj->getCatalogList();
		//dump($_SESSION["quser"]);
		$this->username = $_SESSION["quser"]['realname'];

		$rulesinfo = spClass('chain'); 
		$conditions = array( 'used' => 1 );
        $chainresult = $rulesinfo->findAll($conditions);  // 分页
		$this->chainresult = $chainresult;

		$this -> display('content/Clientfb/lines.html');
	}

	function adddata(){
		$data = $this->spArgs(); // $data是提交上来的数据
		if($data['releasedate'] == null)
		{ $releasedate = time(); }
		else
		{ $releasedate = strtotime($data['releasedate']); }
		
		$newrow = array( // PHP的数组
		'id'=>$data['id'],
		'username'=>$data['username'],
		'userid'=>$_SESSION["quser"]['uid'],
		'picurl'=>$data['picurl'],
		'title'=>$data['title'],
		'ctitle'=>$data['ctitle'],
		'ckeyword'=>$data['ckeyword'],
		'cdirections'=>$data['cdirections'],
		'releasedate'=>$releasedate,
		'content'=>$data['content'],
		'provinceid'=>$data['provinceid'],
	    'cityid'=>$data['cityid'],
		'map'=>$data['map'],
		'tags'=>$data['tags']
		);
		$user = spClass('linesinfo'); 
		$json = json_encode($user->spVerifier($newrow));
		if($json == 'false'){ 
         $newid = $user->create($newrow);
            $Historyrow = array( // PHP的数组
			'types'=>"lines",
			'title'=>$data['title'],
			'linkid'=>$newid,
			'userid'=>$_SESSION["quser"]['uid'],
			'integral'=>6,
			'releasedate'=>$releasedate
			);
			$syshistory = spClass('syshistory'); 
			$syshistory->create($Historyrow);
			$userhistory = spClass('userhistory'); 
			$userhistory->create($Historyrow);

			$user = spClass('lib_user');
			$user_result = $user->find($conditions);
			$conditions = array('uid'=>$_SESSION["quser"]['uid']); 
			$row = array('integral'=>$user_result["integral"] + 6);
			$user->update($conditions, $row);  // 进行新增操作

         }  // 进行新增操作
		echo($json);
	}
	
	function editdata(){
		$data = $this->spArgs(); // $data是提交上来的数据
		$conditions = array('id'=>$data['id']); 
		$releasedate = strtotime($data['releasedate']);
		$row = array('username'=>$data['username'],'picurl'=>$data['picurl'],'title'=>$data['title'],'releasedate'=>$releasedate,'content'=>$data['content'],'provinceid'=>$data['provinceid'],'cityid'=>$data['cityid'],'map'=>$data['map'],'tags'=>$data['tags'],'userid'=>$data['userid'],'ctitle'=>$data['ctitle'],'ckeyword'=>$data['ckeyword'],'cdirections'=>$data['cdirections']);
		$user = spClass('linesinfo');
		$json = json_encode($user->spVerifier($row));
		if($json == 'false'){$user->update($conditions, $row);} 
		echo($json);
	}
	
	function subclass(){
		$data = $this->spArgs(); // $data是提交上来的数据
		
		$conditions = array( 'pid'=>$data['id'] );
		$c_name = spClass('lib_cityinfo'); 
		$data['cityinfo'] = $c_name->findAll($conditions); 

		echo json_encode($data);
	}
	
	function deldata(){
		$data = $this->spArgs(); // $data是提交上来的数据
		$conditions = array('id'=>$data['id']); 
        $user = spClass('linesinfo');
        $data['msg'] = $user->delete($conditions);	
		echo( $data['msg'] );
	}
}
